package com.ds.lens.data.service.dao;

import com.ds.lens.data.service.dao.entity.LensMonitorDefine;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.type.JdbcType;
import org.springframework.stereotype.Repository;

@Repository
public interface LensMonitorDefineSnapshotDao {
    @Delete({
            "insert into lens_monitor_define_snapshot (select * from lens_monitor_define where monitor_id = #{id})"
    })
    int insert(Long id);

    @Select({
            "select",
            "id, operator, threshold_type, threshold_number, window_type, window_time, during, threshold_level, ",
            "notify_data_missing, delay_time, monitor_id, scope,  metric_name, ",
            "metric_filter, metric_aggr, metric_by",
            "from lens_monitor_define_snapshot",
            "where monitor_id = #{id,jdbcType=BIGINT}"
    })
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "operator", property = "operator", jdbcType = JdbcType.TINYINT),
            @Result(column = "threshold_type", property = "thresholdType", jdbcType = JdbcType.INTEGER),
            @Result(column = "threshold_number", property = "thresholdNumber", jdbcType = JdbcType.INTEGER),
            @Result(column = "window_type", property = "windowType", jdbcType = JdbcType.TINYINT),
            @Result(column = "window_time", property = "windowTime", jdbcType = JdbcType.INTEGER),
            @Result(column = "during", property = "during", jdbcType = JdbcType.INTEGER),
            @Result(column = "threshold_level", property = "thresholdLevel", jdbcType = JdbcType.VARCHAR),
            @Result(column = "notify_data_missing", property = "notifyDataMissing", jdbcType = JdbcType.BIT),
            @Result(column = "delay_time", property = "delayTime", jdbcType = JdbcType.INTEGER),
            @Result(column = "monitor_id", property = "monitorId", jdbcType = JdbcType.BIGINT),
            @Result(column = "scope", property = "scope", jdbcType = JdbcType.VARCHAR),
            @Result(column = "metric_name", property = "metricName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "metric_filter", property = "metricFilter", jdbcType = JdbcType.VARCHAR),
            @Result(column = "metric_aggr", property = "metricAggr", jdbcType = JdbcType.TINYINT),
            @Result(column = "metric_by", property = "metricBy", jdbcType = JdbcType.VARCHAR)
    })
    LensMonitorDefine selectByMonitorId(Long id);

}
